<template>
  <div class="app-container">
    <el-input v-model="filterText" placeholder="Filter keyword" style="margin-bottom:30px;" />

    <el-tree
      ref="tree2"
      :data="subjectList"
      :props="defaultProps"
      :filter-node-method="filterNode"
      class="filter-tree"
      default-expand-all
    />

  </div>
</template>

<script>
import listAPI from '@/api/edu/subject';

export default {

  data() {
    return {
      filterText: '',
      subjectList:[],
  // 用于指定里面的key
  defaultProps: {
        children: 'children',
        label: 'title'
      }
    }
  },
  watch: {
    filterText(val) {
      this.$refs.tree2.filter(val)
    }
  },
created(){
    // 要调用才能执行
    this.allSubjectList()
},
  methods: {
    filterNode(value, data) {
      if (!value) return true
      return data.title.toLowerCase().indexOf(value) !== -1
    },
    // 调用api接口
    allSubjectList(){
      listAPI.getSubjectList().then(response=>{
        console.log(response)
        this.subjectList=response.data.list;
      }).catch(error=>{

      })
    }
  }
}
</script>

